<!-- 下面总价 计算后 -->
<template>
  <div>
    <van-submit-bar
      :price="(TotalPaidPrice*100)"
      button-text="提交订单"
      @submit="onSubmit"
      v-if="!disabled"
    >
      <template #tip class="tipbox">
        <div>
          <p>
            <span>
              <span>{{types}}</span>类 共
              <span>{{num}}</span>件商品
            </span>
            <i>总计：</i>
            <bdi>￥{{TotalPrice}}</bdi>
          </p>

          <p>
            <i>运费：</i>
            <bdi>￥{{getFreight}}</bdi>
          </p>

          <p>
            <i>寄送至：</i>
            <span>{{defaultAddress}}</span>
          </p>
          <p>
            <i>收货人：</i>
            <span>{{changesUser}}</span>
          </p>
        </div>
      </template>
    </van-submit-bar>
  </div>
</template>
<script>
export default {
  name: "totalPrice",
  props: {
    defaultAddress: String,
    changesUser: String,
    getFreight: Number,
    Paymentmethods: Number
  },
  data() {
    return {
      types: 0,
      num: 0,
      TotalPrice: 0, // 总价
      PaymentPreferences: 0, // 优惠
      disabled: true
    };
  },
  methods: {
    // 提交订单
    async onSubmit() {
      this.$emit("placeOrder");
    },
    // 获取价格
    getPrice() {
      let PriceNum = this.$store.state.SettlementData;
      this.types = PriceNum.length;
      let changeNum = 0,
        changePrice = 0;
      PriceNum.forEach(element => {
        changeNum += element.num;
        changePrice += element.num * element.selling_price;
      });
      this.num = changeNum;
      this.TotalPrice = changePrice.toFixed(2);
    }
  },
  computed: {
    TotalPaidPrice() {
      if (this.Paymentmethods == 1) {
        console.log("到付");
        this.getFreight = 0;
        let Price = `${this.TotalPrice -
          this.PaymentPreferences +
          this.getFreight}`;
        return Price;
      } else {
        console.log("现付");
        let Price = `${this.TotalPrice -
          this.PaymentPreferences +
          this.getFreight}`;
        console.log(this.TotalPrice, this.getFreight);
        return Price;
      }
    }
  },
  mounted() {
    this.getPrice();
    setTimeout(() => {
      this.disabled = false;
    }, 2000);
  },
  updated() {
    // console.log(this.TotalPaidPrice)
    this.$emit("TotalPriceData", this.TotalPaidPrice);
    // console.log(this.changesUser)
  }
};
</script>
<style lang="scss" scoped>
</style>
